package com.sunjob.loginserver.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sunjob.common.result.Result;
import com.sunjob.loginserver.service.RedisTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Wangzurong
 * @create 2022-08-10 15:41
 * 控制redis缓存的控制类
 */
@Api(value = "redis缓存控制接口",tags = "redis缓存控制接口")
@RestController
public class RedisTemplateController {

    @Autowired
    RedisTemplateService redisTemplateService;

    /**
     * 删除redis缓存 重新加载mysql 实现刷新redis缓存的效果
     *
     * @return
     */
    @ApiOperation(value = "刷新redis缓存")
    @PutMapping("/flushRedis")
    @SaCheckPermission("system:redis:flush")
    public Result<Boolean> flushRedis() {
        redisTemplateService.flushRedis();
        return Result.ok(true, "刷新redis缓存成功");
    }

    /**
     * 删除redis缓存 不做加载操作
     *
     * @return
     */
    @ApiOperation(value = "删除redis缓存")
    @DeleteMapping("/deleteRedis")
    @SaCheckPermission("system:redis:delete")
    public Result<Boolean> deleteRedis() {
        redisTemplateService.deleteRedis();
        return Result.ok(true, "删除redis缓存成功");
    }

    /**
     * 加载数据至redis
     *
     * @return
     */
    @ApiOperation(value = "加载数据至redis缓存")
    @PutMapping("/loadRedis")
    @SaCheckPermission("system:redis:load")
    public Result<Boolean> loadRedis() {
        redisTemplateService.loadRedis();
        return Result.ok(true, "加载数据到redis成功");
    }

}
